#ifndef PUBLICIPINTERFACE_H
#define PUBLICIPINTERFACE_H

#include "Curlplus.h"

bool GetPublicIP(std::string& ip);





bool GetPublicIP(std::string& ip)
{
	ip = "";
	std::string contents;
	contents = Curlplus::get_instance().get("http://www.whatismyip.com/automation/n09230945.asp");
	if (!contents.empty())
	{
		ip = contents;
	}
	if (!ip.empty())
		return true;
	contents = Curlplus::get_instance().get("http://www.ip138.com/ip2city.asp");
	if (!contents.empty())
	{
		std::string::size_type pos1 = contents.find("[");
		std::string::size_type pos2 = contents.find("]");
		if (pos1 != std::string::npos && pos2 != std::string::npos)
		{
			pos1++;
			ip = contents.substr(pos1,pos2 - pos1);
		}
	}
	if (!ip.empty())
		return true;
	contents = Curlplus::get_instance().get("http://www.ip-adress.com/");
	if (!contents.empty())
	{
		string tag = "My IP address is:";
		std::string::size_type pos1 = contents.find(tag);
		if (pos1 != std::string::npos)
		{
			pos1 += strlen(tag.c_str());
			std::string::size_type pos2 = contents.find("</",pos1);
			if (pos2 != std::string::npos)
			{
				ip = contents.substr(pos1,pos2 - pos1);
			}
		}
		
	}
	return !ip.empty();
}


#endif